home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / codecs / mccomponent / mycomponentroutines.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-23  |  4.3 KB  |  146 lines

  1. /*
  2.     File:        MyComponentRoutines.c
  3.  
  4.     Contains:    simple component sample.
  5.  
  6.     Written by: John Wang    
  7.  
  8.     Copyright:    Copyright © 1994-1999 by Apple Computer, Inc., All Rights Reserved.
  9.  
  10.                 You may incorporate this Apple sample source code into your program(s) without
  11.                 restriction. This Apple sample source code has been provided "AS IS" and the
  12.                 responsibility for its operation is yours. You are not permitted to redistribute
  13.                 this Apple sample source code as "Apple sample source code" after having made
  14.                 changes. If you're going to re-distribute the source, we require that you make
  15.                 it clear in the source that the code was descended from Apple sample source
  16.                 code, but that you've made changes.
  17.  
  18.     Change History (most recent first):
  19.                 8/18/1999    Karl Groethe    Updated for Metrowerks Codewarror Pro 2.1
  20.                 
  21.  
  22. */
  23.  
  24. #ifdef THINK_C
  25. #define        applec
  26. #endif
  27.  
  28. #include    <Errors.h>
  29. #include    <Components.h>
  30. #include    <Devices.h>
  31. #include    <Movies.h>
  32. #include    <QuickTimeComponents.h>
  33. #include    <LowMem.h>
  34.  
  35. #include    "MyComponent.h"
  36. #include    "MyComponentRoutines.h"
  37. #include    "FadeScreen.h"
  38. #include    "HideMenuBar.h"
  39.  
  40. /* ------------------------------------------------------------------------- */
  41.  
  42. pascal ComponentResult MyIsPlayerEvent (PrivateGlobals **storage,
  43.             EventRecord *e)
  44. {
  45.     GrafPtr        savePort;
  46.     GDHandle    saveGD;
  47.  
  48.     //    Fade out for the first time.
  49.     if ((**storage).firstTime == true) {
  50.         SwapWindow(storage);
  51.         (**storage).firstTime = false;
  52.     }
  53.     
  54.     //    Handle events
  55.     if (e->what == keyDown) {
  56.         if ((e->message & charCodeMask) == '\t') {
  57.             SwapWindow(storage);
  58.             return(true);
  59.         }
  60.     } else if (e->what == updateEvt) {
  61.         if (e->message == (long) (**storage).backWindow) {
  62.             GetPort(&savePort);
  63.             saveGD = GetGDevice();
  64.             SetPort((**storage).backWindow);
  65.             SetGDevice(GetMainDevice());
  66.             BeginUpdate((**storage).backWindow);
  67.             PaintRect(&(((**storage).backWindow)->portRect));
  68.             EndUpdate((**storage).backWindow);
  69.             SetPort(savePort);
  70.             SetGDevice(saveGD);
  71.             return(true);
  72.         }
  73.     }
  74.     
  75.     //    Handle other events.
  76.     return(MCIsPlayerEvent((**storage).delegate, e));
  77. }
  78.  
  79. //--------------------------------------------------------------------------
  80.  
  81. void SwapWindow(PrivateGlobals **storage)
  82. {
  83.     CGrafPtr            moviePort;
  84.     GDHandle            myDevice;
  85.     Rect                myDeviceRect;
  86.     GrafPtr                savePort;
  87.     GDHandle            saveGD;
  88.     RgnHandle            movieRgn;
  89.     
  90.     //    Get variables
  91.     GetPort(&savePort);
  92.     saveGD = GetGDevice();
  93.     GetMovieGWorld(MCGetMovie((**storage).delegate), &moviePort, nil);
  94.     myDevice = GetMaxDevice(&((**LMGetGrayRgn()).rgnBBox));
  95.     myDeviceRect = (**myDevice).gdRect;
  96.     
  97.     FadeInOut(myDevice, true, 60);
  98.     if ((**storage).fadeStatus == false) {
  99.         //    Hide the menu bar
  100.         (**storage).handleBarStorage = MyHideMenuBar();
  101.  
  102.         //    Modify movie controller.
  103.         (**storage).mcVisible = MCGetVisible((**storage).delegate);
  104.         (**storage).mcAttached = MCIsControllerAttached((**storage).delegate);
  105.         MCSetVisible((**storage).delegate, false);
  106. //        MCSetControllerAttached((**storage).delegate, false);
  107.         movieRgn = MCGetWindowRgn((**storage).delegate, (WindowPtr) moviePort);
  108.         SizeWindow((WindowPtr) moviePort, ((**movieRgn).rgnBBox).right - ((**movieRgn).rgnBBox).left,
  109.                         ((**movieRgn).rgnBBox).bottom - ((**movieRgn).rgnBBox).top, true);
  110.         DisposeRgn(movieRgn);
  111.         
  112.         //    Create back window.
  113.         (**storage).backWindow = NewCWindow(0L, &myDeviceRect, "\pBlack Background", 1, noGrowDocProc, (WindowPtr) -1, false, 0L);
  114.         SelectWindow((**storage).backWindow);
  115.         SetPort((**storage).backWindow);
  116.         SetGDevice(GetMainDevice());
  117.         PaintRect(&(((**storage).backWindow)->portRect));
  118.         
  119.         //    Modify movie window.
  120.         SetPort((GrafPtr) moviePort);
  121.         SetGDevice(GetMainDevice());
  122.         SelectWindow((WindowPtr) moviePort);
  123.         (**storage).fadeStatus = true;
  124.     } else {
  125.         //    Restore menu bar.
  126.         RestoreMenuBar((**storage).handleBarStorage);
  127.  
  128.         //    Restore movie controller.
  129.         MCSetVisible((**storage).delegate, (**storage).mcVisible);
  130.         MCSetControllerAttached((**storage).delegate, (**storage).mcAttached);
  131.         movieRgn = MCGetWindowRgn((**storage).delegate, (WindowPtr) moviePort);
  132.         SizeWindow((WindowPtr) moviePort, ((**movieRgn).rgnBBox).right - ((**movieRgn).rgnBBox).left,
  133.                         ((**movieRgn).rgnBBox).bottom - ((**movieRgn).rgnBBox).top, true);
  134.         DisposeRgn(movieRgn);
  135.  
  136.         //    Dispose back window.
  137.         SelectWindow((**storage).backWindow);
  138.         DisposeWindow((**storage).backWindow);
  139.         (**storage).fadeStatus = false;
  140.     }
  141.     FadeInOut(myDevice, false, 60);
  142.  
  143.     SetPort(savePort);
  144.     SetGDevice(saveGD);
  145. }
  146.